package com.jd.finance.core.controller.admin;


import com.jd.finance.core.service.LoanApplyService;
import com.jd.finance.core.service.impl.AdminUtilsServiceImpl;
import com.jd.finance.result.BaseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 银行表 前端控制器
 * </p>
 *
 * @author LiQingBo
 * @since 2022-05-17
 */
@Slf4j
@Api(tags = "银行中心")
@RestController
@RequestMapping("/admin/core/bankCenter")
public class AdminBankController {

    @Resource
    private LoanApplyService loanApplyService;

    @Resource
    private AdminUtilsServiceImpl adminUtilsServiceimpl;

    @ApiOperation("根据贷款申请id，修改申请状态及时间")
    @PostMapping("/updateApplStatus")
    public BaseResult updateApplStatus(Integer uid, Integer loanAppId, HttpServletRequest request) {
        if(uid == null){
            log.error("uid为空");
            return BaseResult.error().message("uid为空");
        }
        if(loanAppId == null){
            log.error("loanAppId为空");
            return BaseResult.error().message("loanAppId为空");
        }
        if (!adminUtilsServiceimpl.isBank(uid)){
            log.error("当前登录用户不是银行信贷员账户");
            return BaseResult.error().message("当前登录用户不是银行信贷员账户");
        }
        return loanApplyService.updateApplStatus(uid,loanAppId,request);
    }

    @ApiOperation("查看已签署协议的贷款申请")
    @GetMapping("/getSignedLoanApp/{page}/{limit}/{officerId}")
    public BaseResult getSignedLoanApp(
            @ApiParam(value = "当前页码",required = true)
            @PathVariable Long page,

            @ApiParam(value = "每页记录数",required = true)
            @PathVariable Long limit,

            @ApiParam(value = "查询操作的officerId",required = true)
            @PathVariable Integer officerId) {
        if(officerId == null){
            log.error("officerId为空");
            return BaseResult.error().message("officerId为空");
        }
        if (!adminUtilsServiceimpl.isBank(officerId)){
            log.error("当前登录用户不是银行信贷员账户");
            return BaseResult.error().message("当前登录用户不是银行信贷员账户");
        }

        return loanApplyService.getSignedLoanApp(officerId,page,limit);
    }

}

